﻿//排班管理详细计划清单
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.AddPersonGrid = function (config) {
    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/PersonService.aspx?Action=GetPersonByBusiness'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Name', 'IdCard', 'Phone', 'QQ', 'PersonType', 'Sex', 'CarCount', 'Nation', 'NativePlace', 'Address', 'RegisterAddress', 'Description', 'CreateDateStr', 'Enable', 'ModifyDate']
        }),
        remoteStore: true
    });
    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        defaultNum: 8
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    },
    {
        header: '名称',
        dataIndex: 'Name',
        width: 60
    },
    {
        header: '身份证',
        dataIndex: 'IdCard',
        width: 150
    }, {
        header: '电话',
        dataIndex: 'Phone'
    }, {
        header: 'QQ',
        dataIndex: 'QQ'
    }, {
        header: '人员类型',
        dataIndex: 'PersonType'
    },
    {
        header: '性别',
        dataIndex: 'Sex',
        hidden: true
    },
    {
        header: '车辆数目',
        dataIndex: 'CarCount'

    },
    {
        header: '民族',
        dataIndex: 'Nation',
        hidden: true
    },
    {
        header: '籍贯',
        dataIndex: 'NativePlace',

        hidden: true
    },
     {
         header: '现住址',
         dataIndex: 'Address',

         hidden: true
     },
      {
          header: '户籍地址',
          dataIndex: 'RegisterAddress',
          hidden: true
      },
      {
          header: '录入时间',
          dataIndex: 'CreateDateStr',         
          hidden: false
      },
      {
          header: '迁走时间',
          dataIndex: 'ModifyDate',
          hidden: false
      },
      {
          header: '是否使用',
          dataIndex: 'Enable',
          hidden: true
      }];
    FantastPlatform.UI.AddPersonGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.AddPersonGrid, Ext.grid.EditorGridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.AddPersonGrid.superclass.onRender.call(this, ct, position);
    },
    //添加
    onAddPersonClick: function (houseId) {
        var id = GUID();
        currtWind = openWind('../InfoCollection/PersonForm.aspx?houseId=' + houseId, id, '添加人员', 502, 500, 'new_tab')
    },
    //添加1
    onAddPersonFClick: function (houseId) {
        var id = GUID();
        currtWind = openWind('../InfoCollection/PersonForm1.aspx?houseId=' + houseId, id, '添加人员', 502, 500, 'new_tab')
    },
    //修改
    onEditPersonClick: function (houseId) {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/PersonForm.aspx?id=' + fId, id, '编辑人员', 502, 500, null);
            }
        }
    },
    onAddCarClick: function (createPoliceCode, gridType, btnEnable) {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/CarForm.aspx?id=' + fId + '&createPoliceCode=' + createPoliceCode + '&type=' + gridType, id, '编辑车辆', 502, 310, null);
               
            }
        }
    },
    //查看人员详细信息
    onCheckPeopleDetailsClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行查看", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/PersonDetailsForm.aspx?Id=' + fId, id, '查看', 600, 445, null);
            }
        }
    },
    onPersonHistryCheckClick: function (gridId, houseType) {
        this.store.removeAll();
        if (houseType == 'Business') {
            this.store.proxy.conn = { method: 'post', url: '../Service/PersonService.aspx?Action=GetPersonByBusinessHistry' };
        } else if (houseType == 'HouseHold') {
            this.store.proxy.conn = { method: 'post', url: '../Service/PersonService.aspx?Action=GetPersonByHouseHoldHistry' };
        }
        this.store.baseParams = { id: gridId };
        this.store.load({ params: { start: 0, limit: this.paperBar.defaultNum, dir: '', sort: ''} });

    },
    onPersonNowCheckClick: function (gridId, houseType) {
        this.store.removeAll();
        if (houseType == 'Business') {
            this.store.proxy.conn = { method: 'post', url: '../Service/PersonService.aspx?Action=GetPersonByBusiness' };
        } else if (houseType == 'HouseHold') {
            this.store.proxy.conn = { method: 'post', url: '../Service/PersonService.aspx?Action=GetPersonByHouseHold' };
        }
        this.store.baseParams = { id: gridId };
        this.store.load({ params: { start: 0, limit: this.paperBar.defaultNum, dir: '', sort: ''} });

    },
    //修改1
    onEditPersonFClick: function (houseId) {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var type = node[0].get('PersonType')
                if (type == "房主") {
                    type = "Owner";
                } else if (type == "普通用户") {
                    type = "Person";
                } else if (type == "承租人") {
                    type = "Leader";
                }
                var id = GUID();
                currtWind = openWind('../InfoCollection/PersonForm1.aspx?id=' + fId + '&type=' + type, id, '编辑人员', 502, 500, null);
            }
        }
    },
    onViewDetailsClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行操作", "");
            } else {
                var fId = node[0].get('Id');
                if (fId != 0) {
                    var id = GUID();
                    detailWind = openWind('UI/PoliceManToScheduleGrid.aspx?id=' + fId, id, '查看该班次的警员或添加备注', 550, 350, 'edit');
                }
                else {
                    showErrorMessage("操作失败", "该记录还未保存", "");
                }
            }
        }
    }
});